<template>
	<view class="content">
		<view class="info">
			<view class="item">
				<view>用户头像</view>
				<image :src="img" @click="changeImg()" class="img_user"></image>
			</view>
			<view class="item">
				<view>昵称</view>
				<view>{{info.short_name}}</view>
			</view>
			<view class="item">
				<view>Email</view>
				<view>{{info.email}}</view>
			</view>
			<view class="item">
				<view>真实姓名</view>
				<view>{{info.real_name}}</view>
			</view>
			<view class="item">
				<view>身份证号</view>
				<view>{{info.idno}}</view>
			</view>
			<view class="item">
				<view>手机号码</view>
				<view>{{info.mobile}}</view>
			</view>
			<!-- <view class="item">
				<view>性别</view>
				<view>女</view>
			</view> -->
			<!-- <view class="item">
				<view>出生日期</view>
				<view>1998-09-19</view>
			</view> -->
			<!-- <view class="item">
				<view>最高学历</view>
				<view>本科</view>
				<uni-icons type="right" color="#999999" size="18"></uni-icons>
			</view> -->
		</view>
		<view class="default_btn" @click="save">保存</view>
	</view>
</template>

<script>
	import {
		userInfo,
		fileUp,
		editUserInfo
	} from '@/common/js/index.js'
	export default {
		data() {
			return {
				info: '',
				img: '',
			}
		},
		onLoad() {
			this.user()
		},
		methods: {
			save() {
				editUserInfo({
					header_img: this.img
				}).then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 200) {
						setTimeout(function() {
							uni.navigateBack()
						}, 2000)
					}
				})
			},
			user() {
				userInfo().then(res => {
					console.log(res);
					this.info = res.data
					this.img = res.data.user_pic
				})
			},
			changeImg(num) {
				console.log(this.userId);
				var that = this
				uni.chooseImage({
					count: 1,
					sizeType: ["compressed"],
					success(response) {
						console.log(response);
						// 选择图片后, 返回的数据
						var fileUrl = response.tempFilePaths[0]
						console.log(fileUrl);
						fileUp({
							file: fileUrl
						}).then(res => {
							var info = JSON.parse(res)
							if (info.code == 200) {
								that.img = info.data[0]
								console.log(that.img);
								// that.save()
							} else {
								uni.showToast({
									title: info.msg,
									icon: 'error',
									duration: 3000
								})
							}
						})
					}
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	.content {
		/* background: white; */
		position: relative;
		overflow: hidden;
	}

	.info {
		margin: 40rpx 30rpx 80rpx;
		padding: 24rpx 30rpx 40rpx;
		background-color: white;
		border-radius: 12rpx;

		.item {
			height: 110rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 2rpx solid #EEEEEE;

			view {
				&:nth-of-type(1) {}

				&:nth-of-type(2) {
					flex: 1;
					text-align: right;
					font-size: 26rpx;
					color: #999999;
				}
			}

			.img_user {
				width: 84rpx;
				height: 84rpx;
				border-radius: 50%;
			}
		}
	}
</style>